package com.rest.demo.concurrent;

import java.util.Random;
import java.util.stream.IntStream;

/**
 * @author Administrator
 * @decription
 * @Date 2018-02-01 15:19
 */
public class BufferTestDemo {
    public static void main(String[] args) {

        Buffer buffer = new Buffer();

        IntStream.range(0,5).forEach(i -> new Thread(() -> {
            try {
                buffer.put(new Random().nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start());

        IntStream.range(0,10).forEach(i -> new Thread(() -> {
            try {
                buffer.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start());
    }
}
